import PySpin
import matplotlib.pyplot as plt
import sys
import keyboard

class PoinGreyCam:
    def __init__(self):
        self.system = PySpin.System.GetInstance()
        version = self.system.GetLibraryVersion()
        print('Library version: %d.%d.%d.%d' % (version.major, version.minor, version.type, version.build))

        # Retrieve list of cameras from the system
        cam_list = self.system.GetCameras()
        print('cam_list:', cam_list)



        num_cameras = cam_list.GetSize()
        print('Number of cameras detected: %d' % num_cameras)

        if num_cameras == 0:
            # Clear camera list before releasing system
            cam_list.Clear()

            # Release system instance
            self.system.ReleaseInstance()

            print('Not enough cameras!')
            input('Done! Press Enter to exit...')


        self.cameras = self.system.GetCameras()
        self.cam_list = []

    def openCommunications(self):
        pass

    def returnCamList(self):
        '''

        :return: 放回一个相机名字的列表到combo
        '''
        camList = []
        for i,cam in enumerate(self.cameras):
            # camList.append(cam.DeviceUserID())
            nodemap_tldevice = cam.GetTLDeviceNodeMap()
            node_device_model_number = PySpin.CStringPtr(nodemap_tldevice.GetNode('DeviceModelName'))
            # node_device_serial_number = PySpin.CStringPtr(nodemap_tldevice.GetNode('DeviceSerialNumber'))
            device_model_number = node_device_model_number.GetValue()
            # device_serial_number = node_device_serial_number.GetValue()
            print(device_model_number)
            # print(type(node_device_model_number))
            camList.append(device_model_number )
        return camList

def main():
    cams = PoinGreyCam()
    cams.returnCamList()



if __name__ == '__main__':
    main()

